package function;

import model.Author;
import model.GetAuthors;

import java.util.List;
import java.util.Optional;

public class Max_Min {
    public static void main(String[] args) {
        List<Author> authors = GetAuthors.getAuthors();
        Optional<Integer> max = authors.stream()
                .flatMap(author -> author.getBooks().stream())
                .distinct()
                .map(book -> book.getScore())//将Book转换为int(分数)的流
                .max((o1, o2) -> o1 - o2);
        System.out.println("maxScore:"+max.get());

        Optional<Integer> min = authors.stream()
                .flatMap(author -> author.getBooks().stream())
                .distinct()
                .map(book -> book.getScore())//将Book转换为int(分数)的流
                .min((o1, o2) -> o1 - o2);
        System.out.println("mixScore:"+min.isPresent());
    }
}
